﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Bymed.SpineScan.DataModel;
using Bymed.SpineScan.Repository.Interface;

namespace Bymed.SpineScan.Repository.EntityFramework
{
    public class AttendingDoctorRepository : RepositoryBase<AttendingDoctor>, IAttendingDoctorRepository
    {
        public AttendingDoctorRepository(SpineScanContext dataContext) : base(dataContext) { }

        /// <summary>
        /// Add or update AttendingDoctor.
        /// </summary>
        /// <param name="entity">The AttendingDoctor will be updated if it is existing or added if it cannot be found.</param>
        public override void AddOrUpdate(AttendingDoctor entity)
        {
            var matchedDoctorCount = GetRowCount(d => d.DoctorTimestamp == entity.DoctorTimestamp);

            if (matchedDoctorCount == 0)
            {
                Add(entity);
            }
            else
            {
                Update(entity);
            }
        }
    }
}
